﻿using Microsoft.EntityFrameworkCore;
using Shopping_Cart.Models;
using System.Collections.Generic;

namespace Shopping_Cart.Data
{
    public class MyContext : DbContext
    {
        public MyContext(DbContextOptions<MyContext> options) : base(options)
        {

        }

        public DbSet<Product> Products { get; set; }
        public DbSet<Order> Orders { get; set; }
        public DbSet<OrderDetail> OrderDetails { get; set; }

        protected override  void OnModelCreating(ModelBuilder modelBuilder)
        {
            List<Product> products = new List<Product>()
            {
                new Product()
                {
                    ProductId = 1,
                    Title = "title1",
                    Text = "text1",
                    Price = 1000,
                    ImageName="imagename1"
                },
                new Product()
                {
                    ProductId = 2,
                    Title = "title2",
                    Text = "text2",
                    Price = 2000,
                    ImageName="imagename2"
                },
                new Product()
                {
                    ProductId = 3,
                    Title = "title3",
                    Text = "text3",
                    Price = 3000,
                    ImageName="imagename3"
                },
                new Product()
                {
                    ProductId = 4,
                    Title = "title4",
                    Text = "text4",
                    Price = 4000,
                    ImageName="imagename4"
                },
                new Product()
                {
                    ProductId = 5,
                    Title = "title5",
                    Text = "text5",
                    Price = 5000,
                    ImageName="imagename5"
                },
                new Product()
                {
                    ProductId = 6,
                    Title = "title6",
                    Text = "text6",
                    Price = 6000,
                    ImageName="imagename6"
                },
                new Product()
                {
                    ProductId = 7,
                    Title = "title7",
                    Text = "text7",
                    Price = 7000,
                    ImageName="imagename7"
                },
                new Product()
                {
                    ProductId = 8,
                    Title = "title8",
                    Text = "text8",
                    Price = 8000,
                    ImageName="imagename8"
                },

            };
            modelBuilder.Entity<Product>().HasData(products);
            base.OnModelCreating(modelBuilder);

        }

        //protected override void OnModelCreating(ModelBuilder modelBuilder)
        //{
        //    modelBuilder.Entity<OrderDetail>()
        //        .HasOne(o => o.Product)
        //        .WithMany(p => p.OrderDetails)
        //        .HasForeignKey(f => f.ProductId);

        //    modelBuilder.Entity<OrderDetail>()
        //        .HasOne(o => o.Order)
        //        .WithMany(od => od.OrderDetails)
        //        .HasForeignKey(f => f.OrderId);

        //    base.OnModelCreating(modelBuilder);
        //}
    }
}
